package com.ruoyi.client.controller;


import com.ruoyi.client.pojo.vo.HomeCarouselVo;
import com.ruoyi.client.pojo.vo.HomeGoodsVo;
import com.ruoyi.client.pojo.vo.HomeInfoVo;
import com.ruoyi.client.service.HomeService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Anonymous //允许匿名访问
@CrossOrigin

@Api(tags = "01.首页模块")
@RestController
@RequestMapping("home")
public class HomeController {

    @Resource
    HomeService homeService;

    @ApiOperation("获取首页数据")
    @GetMapping("/index")
    public R<HomeInfoVo> index(){
        HomeInfoVo homeInfoVo = new HomeInfoVo();
        //获取轮播数据
        List<HomeCarouselVo> carouselItems = homeService.getCarouselVoList();
        //获取打折商品
        List<HomeGoodsVo> discountItems = homeService.geHomeGoodsVoList(2);
        //获取新品
        List<HomeGoodsVo> newConditionItems = homeService.geHomeGoodsVoList(3);
        //获取热销商品
        List<HomeGoodsVo> hotSaleItems = homeService.geHomeGoodsVoList(4);
        //组装数据
        homeInfoVo.setCarouselItems(carouselItems); //轮播数据
        homeInfoVo.setDiscountItems(discountItems); //折扣数据
        homeInfoVo.setNewConditionItems(newConditionItems); //新品数据
        homeInfoVo.setHotSaleItems(hotSaleItems); //热销数据
        return R.ok(homeInfoVo);
    }
}
